var util = require('../../utils/util.js');
var utilMd5 = require('../../utils/md5.js');
var app = getApp();
var base64 = require('../../utils/Base64.js');
Page({
  data: {
    util: util,

    colorSet: '',

    shopData: []
  },

  onLoad: function(options) {

    var that = this;
    
    wx.getSystemInfo({
      success: function(res) {
        var isIphone_x = (res.model.indexOf('iPhone X') >= 0);
        that.setData({
          isIphone_x: isIphone_x
        });
      }
    });

    this.loadUserByCata();

  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    var that = this;
    //获取颜色配置
    app.getColorSetData(function(color) {
      that.setData({
        colorSet: color
      })
      that.resetNavColor();
    });
  },

  onShow:function(){

  },

  //设置titlebar 样式
  resetNavColor: function() {
    var bg_color = '#f0f0f0';
    var fg_color = '#000000';
    if (this.data.colorSet) {
      bg_color = this.data.colorSet.titlebg;
      fg_color = this.data.colorSet.titlefont;
    }
    wx.setNavigationBarColor({
      frontColor: fg_color,
      backgroundColor: bg_color
    })
  },

  // 读取门店类型的用户
  loadUserByCata: function () {
    var that = this;
    wx.showLoading({
      title: 'loading',
    })
    var params = {
      publickey: util.publiccode,
      ac: "getcatauser",
      orgid: util.orgid,
      usercata: '20',
      shopuid: '',
      page: 1,
      num: 100
    }
    util.api({
      data: params,
      success: function (responseData) {
        var result = responseData.data;
        console.log("门店数据：", result);
        if (!result.msg) {
            that.setData({
              shopData: result
            });
        } else {
            that.setData({
              shopData: []
            });
        }
        
        wx.hideLoading();
      }
    });
  },

  allAction: function (e) {
    wx.showModal({
      title: '提示',
      content: '请选择功能',
      confirmText: '演示',
      cancelText: "调试",
      success: function (res) {
        let path = '';
        if (res.confirm) {//演示
          path = "/pages/gui_list/gui_list?demo=true";
        } else {//调试这个门店的机器
          path = "/pages/gui_list/gui_list?debug=true";
        }
        wx.navigateTo({
          url: path,
        })
      }
    })
  },

  catchAction:function(e){
    console.log("aaaaaaaa", e);
    let userInfo = e.currentTarget.dataset.userinfo;
    let mendianId = userInfo.uid;
    wx.showModal({
      title: '提示',
      content: '请选择功能',
      confirmText:'营收',
      cancelText:"调试",
      success: function(res){
        let path = '';
        if(res.confirm){//去查看这个门店的营收
          path = "/pages/income/income?mendianid=" + mendianId;
        } else {//调试这个门店的机器
          path = "/pages/gui_list/gui_list?debug=true&mendianid=" + mendianId;
        }
        wx.navigateTo({
          url: path,
        })
      }
    })
  },

  goAtherPage: function(e) {
    wx.navigateTo({
      url: e.currentTarget.dataset.link
    })
  },
  goAtherPageRedirect: function(e) {
    var url = e.currentTarget.dataset.link;
    wx.redirectTo({
      url: url
    })
  },

  //保存formId
  submitFormId: function(e) {
    app.saveFormId(e.detail.formId);
  },



})